package com.health.user.config;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zhexueqi
 * @ClassName RedissonConfig
 * @since 2024/7/5    17:28
 */
@Configuration
public class RedissonConfig {

    @Value("${spring.data.redis.host}")
    private String redisHost;

    @Value("${spring.data.redis.port}")
    private String redisPort;

    @Value("${spring.data.redis.password}")
    private String password;


    @Bean
    public RedissonClient RedissonClient() {
        // 1. 创建配置对象
        Config config = new Config();
        String redisAddress = String.format("redis://%s:%s", redisHost, redisPort);
        //单个redis用Single，集群用Cluster
        config.useSingleServer().setAddress(redisAddress).setPassword(password).setDatabase(3);

        // 2. 创建redisson 实例
        // Sync and Async API
        return Redisson.create(config);
    }
}
